#include "stdio.h"
#include "stdlib.h"

// calculate factorial: n! = n * (n - 1)!
int fact(int n)
{
    // exit
    if (n <= 1)
        return 1;
    else
        return n * fact( n - 1);
}

// calculate power: x^n = x * x^(n-1)
int power(int x, int n)
{
    // exit
    if (n == 0)
        return 1;
    else
        return x * power(x, n - 1);
}


// calculate Fibonacci
int fib(int n)
{
    if (n < 2)
        return n;
    else
        return fib(n - 1) + fib(n - 2);
}

// the main function to test recursive functions
int main()
{
    int n = 10;
    int x = 2;

    printf("n! = %d\n", fact(n));
    printf("%d^%d = %d\n", x, n, power(x, n));
    printf("Fibonacci of %d: ", n);
    
    for (int i = 1; i <= n; i++)
        printf("%d ", fib(i));
    printf("\n");

    return 0;
}
